package com.zhiyou100.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhiyou100.dao.VisitorsDao;
import com.zhiyou100.model.Visitors;
import com.zhiyou100.service.VisitorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yql.myutil.MyDate;

import java.util.List;

/**
 * @author YQL
 */
@Service
public class VisitorsServiceImpl implements VisitorsService {

    @Autowired
    private VisitorsDao visitorsDao;

    @Override
    public Page<Visitors> getVisitorsPage(Integer pageNumber, Integer vstatus) {
        if (pageNumber == null || pageNumber <= 0) {
            pageNumber = 1;
        }
        if (vstatus == null || vstatus < 0 || vstatus > 3) {
            vstatus = 0;
        }
        QueryWrapper<Visitors> query
                = new QueryWrapper<>();
        query.eq("vstatus", vstatus);
        Page<Visitors> page
                = new Page<>(pageNumber, 10);
        return visitorsDao.selectPage(page, query);
    }

    @Override
    public List<Visitors> getNow() {
        return visitorsDao.getNow();
    }

    @Override
    public Page<Visitors> getRecord(Integer pageNumber) {
        if (pageNumber == null || pageNumber <= 0) {
            pageNumber = 1;
        }
        QueryWrapper<Visitors> query = new QueryWrapper<>();
        query.lt(true, "vreserve_time", MyDate.builder().build().toString());
        Page<Visitors> page
                = new Page<>(pageNumber, 10);
        return visitorsDao.selectPage(page, query);
    }

    /**
     * # :L:
     * @param args
     */
    public static void main(String[] args) {
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 100; i < 1000; i++) {
            if (i % 3 != 0) {
                sum1 += i;
            } else {
                sum2 += i % 10;
                System.out.println(sum2);
            }
        }
        System.out.println(sum2);
        System.out.println(sum1);
    }
}
